package com.laundry.service.impl;

import com.laundry.dao.ServiceTypeDao;
import com.laundry.entity.ServiceType;
import com.laundry.service.ServiceTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class ServiceTypeServiceImpl implements ServiceTypeService {

    @Autowired
    private ServiceTypeDao serviceTypeDao;
    
    @Override
    public List<ServiceType> findAll() {
        return serviceTypeDao.findAll();
    }
    
    @Override
    public ServiceType findById(Long id) {
        return serviceTypeDao.findById(id).orElse(null);
    }
    
    @Override
    public ServiceType save(ServiceType serviceType) {
        serviceType.setCreateTime(new Date());
        serviceType.setUpdateTime(new Date());
        return serviceTypeDao.save(serviceType);
    }
    
    @Override
    public ServiceType update(ServiceType serviceType) {
        ServiceType existServiceType = serviceTypeDao.findById(serviceType.getId()).orElse(null);
        if (existServiceType == null) {
            return null;
        }
        
        serviceType.setCreateTime(existServiceType.getCreateTime());
        serviceType.setUpdateTime(new Date());
        return serviceTypeDao.save(serviceType);
    }
    
    @Override
    public void deleteById(Long id) {
        serviceTypeDao.deleteById(id);
    }
} 